
#pragma once

#include "../Main.h"
#include "../SuperTree.h"
#include "../TypedList.h"

class FFileInfo;
class FArchive;
class Element;
class TextureManager;

enum PRESET_RESOURCE_TYPE 
{
	PRESET_RESOURCE_IMAGE,
	PRESET_RESOURCE_SHADER
};

class Resource
{
public:
	
	Resource()
	{
		xHash = INVALID_STRING_HASH;
		iType = PRESET_RESOURCE_IMAGE;
		bIsStandardResource = false;
	}
	
	StringHash				xHash;
	PRESET_RESOURCE_TYPE	iType;
	bool					bIsStandardResource;
};

class Preset
{
	friend class Element;
	
public:
	
	Preset();
	virtual ~Preset();
	
	void Clear();
    void CreateWorkingFiles();
	
	bool LoadFromFile( const char* const szFilename );
	bool SaveToFile( const char* const szFilename ) const;
    const char* GetFilename() { return m_szFileName; };
		
	FHandle CreateElement( const FFileInfo* pxFFileInfo, const FHandle uParent = TREE_HANDLE_HEAD, const FHandle uInsertAfter = INVALID_HANDLE );
	FHandle CreateElement( const Element* pxCopyFromElement, const FHandle uParent = TREE_HANDLE_HEAD, const FHandle uInsertAfter = INVALID_HANDLE );
	
	FHandle CreateResource( const FFileInfo* pxFFileInfo );
	FHandle CreateResource( const Resource* pxCopyFromResource );
	
	void RemoveElement( const FHandle uElementID );
	void MoveElement( const FHandle uElementID, const FHandle uParent, const FHandle uInsertAfter );
	
	Element* GetElement( const FHandle uElement );
	const Element* GetElement( const FHandle uElement ) const;
	
	SuperTree<Element>* GetElements();
	const SuperTree<Element>* GetElements() const;
	
	void RemoveResource( const FHandle uResourceID );
	
	Resource* GetResource( const FHandle uResource );
	const Resource* GetResource( const FHandle uResource ) const;
	
	TypedList< Resource >* GetResources();
	const TypedList< Resource >* GetResources() const;
	
	void Update();
	void Render();
	
	void Restart() { m_bNeedsInit = true; }

protected:
	
	void Init();
	void RenderInternal_Recursive( FHandle xHead );
	
	TextureManager* m_pxTextureManager;

	SuperTree<Element>*		m_pxElements;
	TypedList< Resource >*	m_pxResources;

    FArchive* m_pxArchive;

	bool m_bNeedsInit;
	
	mutable char m_szFullPath[ FRIDGE_MAX_PATH ];
	mutable char m_szFileName[ FRIDGE_MAX_PATH ];
	mutable char m_szWorkingDirectory[ FRIDGE_MAX_PATH ];
};


// eof
